package com.excemly.library.common;

import java.util.Map;
//通用API响应类，封装接口返回的状态码（ code ）、数据（ data ）和消息（ message ）。
public class ApiResponse {
    private int code;
    private Object data;
    private String message;

    public ApiResponse(int code, Object data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public static ApiResponse success(Object message, Object data) {
        return new ApiResponse(200, data, message != null ? message.toString() : "");
    }

    public static ApiResponse success(Object data) {
        return success(null, data);
    }

    public static ApiResponse success(String message) {
        return success(message, null);
    }

    public static ApiResponse error(int code, String message) {
        return new ApiResponse(code, null, message);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}